<?php
/**
 * Invite(社招人员管理)
 */
namespace Admin\Controller;

use Common\Controller\AdminbaseController;

class InviteController extends AdminbaseController
{
    protected $invite_model;

    public function _initialize()
    {
        parent::_initialize();
       $this->invite_model = D("Common/Invite");
    }

    // 后台社招人员列表
    public function index()
    {
        $state = I('request.state','');
        parent::dict_select(array(array(
            'code' => 'USER_SH_STATE',
            'name' => 'state',
            'text' => '审核状态',
            'value' => $state
        )
        ));
        $where = array();
        $where['deleted_time'] = array('exp','is null');
        if($state){
            $where['state']=$state;
        }

        $count = $this->invite_model->where($where)->count();
        $page = $this->page($count, 20);
        $list = $this->invite_model->order("created_time DESC")
            ->where($where)
            ->limit($page->firstRow . ',' . $page->listRows)
            ->select();
        $this->assign('list', $list);
        $this->assign("page", $page->show('Admin'));
        $this->display();
    }

    // 企业新增页面
    public function add()
    {
        parent::dict_select(array(array(
            'code' => 'COM_PJXZ',
            'name' => 'pay',
            'text' => '平均薪资'
        ), array(
            'code' => 'COM_SSHT',
            'name' => 'trade',
            'text' => '所属行业'
        ), array(
            'code' => 'COM_XZ',
            'name' => 'nature',
            'text' => '企业性质'
        ), array(
            'code' => 'COM_GM',
            'name' => 'scale',
            'text' => '企业规模'
        )
        ));
        $this->display();
    }


    /**
     * 修改用户状态
     * 状态类型参考数字字典USER_SH_STATE
     */
    public function changer_state()
    {
        $id = I("get.id",0,'intval');
        $state = I("get.state",0,'intval');
        if(isset($state)&&$state==2){
            $this->invite_model->pass_time=time();
        }
        $this->invite_model->state=$state;
        $rs= $this->invite_model->where('id='.$id)->save();
        if ($rs!==false) {
            $this->success("成功！");
        } else {
            $this->error("失败！");
        }
    }
    
    /**
     * 删除社招人员
     * 增加删除时间做软删除
     */
    public function delete() {
        $id = I("get.id",0,'intval');
        $this->invite_model->deleted_time = time();
        $rs= $this->invite_model->where('id='.$id)->save(); // 根据条件更新记录
       if ($rs!==false) {
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
    }
}
